﻿namespace EyeOpen.Webcam.Silverlight
{
	using System.ServiceModel;
	using System.Windows.Controls;

	public static class PageExtensions
	{
		public static T CreateService<T>(this Control control, string serviceUrl)
		{
			var endPoint = new EndpointAddress(serviceUrl);
			var binding =
				new BasicHttpBinding
				{
					MaxBufferSize = int.MaxValue,
					MaxReceivedMessageSize = int.MaxValue,
				};

			binding.Security.Mode = BasicHttpSecurityMode.None;

			return
				new ChannelFactory<T>(binding, endPoint).CreateChannel();
		}		
	}
}